<template>
  <a-table
    :columns="columns"
    :data-source="tableList"
    :pagination="pagination"
    :scroll="{ y: '780px' }"
    @change="handleChangePage"
  >
    <template #bodyCell="{ record, column }">
      <template v-if="column.dataIndex === 'address'">
        {{ record.region }}{{ record.address }}
      </template>
      <template v-if="column.dataIndex === 'cover'">
        <a-image
          :preview="true"
          width="60px"
          height="60px"
          :src="record.cover"
          alt="封面"
        ></a-image>
      </template>
      <template v-if="column.dataIndex === 'price'">
        <span>{{ record.price / 100 }}元</span>
      </template>
      <template v-if="column.dataIndex === 'status'">
        <span :class="[record.status === 'OPEN' ? 'active' : '']">{{
          statusText[record.status as 'CLOSE' | 'OPEN']
        }}</span>
      </template>
      <template v-if="column.dataIndex === 'createdAt'">
        {{ dayjs(record.createdAt).format('YYYY-MM-DD HH:mm:ss') }}
      </template>
      <template v-if="column.dataIndex === 'operation'">
        <a-button @click="openEdit(record)" type="link">编辑</a-button>
      </template>
    </template>
  </a-table>
</template>
<script lang="ts" setup>
import dayjs from 'dayjs'
import type { FormState } from './type.dict'
const emit = defineEmits(['changePagination', 'openEdit'])
defineProps<{
  tableList: FormState[]
  pagination: {
    total: number
    current: number
    pageSize: number
  }
}>()
const statusText = {
  CLOSE: '下架',
  OPEN: '上架',
}
const handleChangePage = (e: { current: number; pageSize: number }) => {
  emit('changePagination', {
    pageSize: e.pageSize,
    current: e.current,
  })
}
const columns = [
  {
    title: '名称',
    dataIndex: 'name',
    width: 80,
  },
  {
    title: '积分值',
    dataIndex: 'point',
    width: 100,
  },
  {
    title: '价格',
    dataIndex: 'price',
    width: 100,
  },
  {
    title: '状态',
    dataIndex: 'status',
    width: 90,
  },
  {
    title: '封面',
    dataIndex: 'cover',
    width: 100,
  },
  {
    title: '操作',
    dataIndex: 'operation',
    key: 'operation',
    width: 90,
    fixed: 'right',
  },
]
const openEdit = (record: FormState) => {
  emit('openEdit', record)
}
</script>
<style lang="stylus" scoped>
@import "@/assets/antgloab-ant.css";

.active {
  color: #1677ff;
}
.red{
  color red
}
.modal-center {
  display flex
  flex-direction column
  align-items center
  justify-content center
  margin 46px 0 40px

  .modal-text {
    margin 16px 0 56px
    font-size 16px
    font-weight 500
  }

  .modal-btn {
    width 200px
    height 46px
    border-radius: 4px
    background #3483FF
    font-weight 500
    font-size 16px
  }
}

:deep(.ant-table-body::-webkit-scrollbar) {
  width: 0;
}

.header_text {
  color: rgba(0, 0, 0, 0.88);
  font-weight: 600;
}
</style>
